package com.ddwanglife.juc;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.Arrays;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
//@Accessors(chain=true)
class User{
    private Integer id;
    private String userName;
    private Integer age;
}

/**
 * 题目：按照给出数据，找出同时满足以下条件的用户，也即以下条件全部满足
 * 偶数ID
 * 年龄大于24
 * 用户名转为大写
 * 用户名字字母顺序倒排
 * 只输出一个用户名字
 */
public class StreamDemo {
    public static void main(String[] args) {
        User u1 = new User(11,"a",23);
        User u2 = new User(12,"b",24);
        User u3 = new User(13,"c",22);
        User u4 = new User(14,"d",28);
        User u5 = new User(15,"e",26);
        User u6 = new User(16,"f",27);
        List<User> list = Arrays.asList(u1,u2,u3,u4,u5,u6);
        /*list.stream().filter(u->{
          return u.getId()% 2 == 0 && u.getAge()>24;
        }).map(u ->{
            return u.getUserName().toString().toUpperCase();
        }).sorted((t1,t2)->{
            return t2.compareTo(t1);
        }).limit(1).forEach(System.out::println);*/
        list.stream()
                .filter(u-> u.getId()% 2 == 0 && u.getAge()>24)
                .map(u -> u.getUserName().toString().toUpperCase())
                .sorted((t1,t2)-> t2.compareTo(t1)).limit(1).forEach(System.out::println);
    }
}
